<?php
/**
 * JSON Interface to save contact status change
 * 
 */

use Hive\Mission;
$xview = Xview::instance();

$contactid = $xview->val('contactid');
$missionid = $xview->val('missionid');
$newstatus = $xview->val('newstatus');
$role = Mission\Partner::ROLE_CANDIDATE;
try {
	$partner = Fox\Dao::load(Mission\Partner::className(),"$missionid:$role:$contactid");
	if($partner->status != $newstatus) {
		$partner->status = $newstatus;
		$partner->update();
		Fox\Message::Success(Msg(Hive::BUNDLE,Hive::MISSION_CANDIDATS_STATUS_SAVED));
	}
	
} catch(Fox\Object\Exception\NotExist $e) {
	Fox\Message::Error($e);
} catch(Fox\Object\Exception\Save $e) {
	Fox\Message::Error($e);
}

echo $xview->messages(true,true);
/*
\Fox\Background\Task::run($status, function ($status) use ($document,$grouping_id,$grouping_type)  {
	$status->start();
	
});
*/